package com.kd.juhaowan.ui.adapter;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

public class CommonFragmentPagerAdapter extends FragmentPagerAdapter {

    private final List<Fragment> fragments;
    private String[] titles;

    public CommonFragmentPagerAdapter(FragmentManager fragment, List<Fragment> fragments) {
        super(fragment);
        this.fragments = fragments;
    }

    public CommonFragmentPagerAdapter(FragmentManager fragment, List<Fragment> fragments, String[] tit) {
        super(fragment);
        this.fragments = fragments;
        this.titles = tit;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        if(titles!=null&&titles.length>0){
            return titles[position];
        }else {
            return super.getPageTitle(position);

        }
    }
}
